﻿using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IDAdmin.Lib.DataLayer;
namespace IDAdmin.Pages
{
    public partial class AutoChangeData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string type = Request.QueryString["type"];
                string _date = Request.QueryString["date"];
                DateTime day = DateTime.Today;
                DateTime yesterday = AddWorkdays(day, -1);
                switch (type)
                {
                    case "au":
                        bool statusAU = WebDB_N.InsertAuCasToSqlserver(day.ToString("MM/dd/yyyy"));
                        bool b = WebDB_N.InsertStatsAU(yesterday.ToString("yyyy-MM-dd"));
                        break;
                    case "goldshop":
                        if (_date != null)
                        {
                            day = Convert.ToDateTime(_date).AddDays(1);
                            yesterday = AddWorkdays(day, -1);
                        }
                       // List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(day, day);
                      //  bool statusGoldshop = WebDB_N.InsertGoldShopDataToSqlserver(dateTimeList);
                        //string todate = "03/12/2015";
                        //string enddate = "06/09/2015";
                        //DateTime begind = Convert.ToDateTime(todate);
                        //DateTime endd = Convert.ToDateTime(enddate);
                        List<DateTime> dateTimeListB = IDAdmin.Common.ConverterWorkData.getDateListBetween(yesterday, yesterday);
                        bool statsInsertConsume = WebDB_N.InsertStatsComsume(dateTimeListB);
                        break;
                    case "pcard":
                        bool a = WebDB_N.InsertPcard(yesterday);
                        break;
                    case "ccu":
                        bool statusCCU = WebDB_N.InsertCcuCasToSqlserver(yesterday.ToString("MM/dd/yyyy"));
                       // bool checkStatus = WebDB_N.checkCCU(yesterday);
                        break;
                    case "test":
                        bool z = WebDB_N.testcron();
                        break;
                    case "ccu5":      
                         bool s = WebDB_N.InsertCcuCasToSqlserver(day.ToString("MM/dd/yyyy"));
                       // WebDB_N.checkCCUToday(DateTime.Today);
                        break;
                }
            }
            catch (Exception ex)
            {

            }           
        }
        public static DateTime AddWorkdays(DateTime originalDate, int workDays)
        {
            DateTime tmpDate = originalDate;
            int a = workDays > 0 ? 1 : -1;
            while (workDays != 0)
            {
                tmpDate = tmpDate.AddDays(a);
                workDays -= a;
                //workDays--;
            }
            return tmpDate;
        }
    }
}